let productList = document.querySelector("#productList");

const xhr = new XMLHttpRequest();
xhr.open("get","http://chst.vip:1234/api/getindexmenu",true)
xhr.onload = function(){
    if(xhr.status === 200){
        let res = JSON.parse(xhr.responseText);
        console.log(res);
        // console.log(res.result);

        let divs = "";
        res.result.forEach((item,index) => {
            divs += `<a href = "./html/${item.titlehref}">
                        <div class='box'>
                        ${item.img}
                        <p>${item.name}</p>
                        </div>
                    </a>`
        });
        productList.innerHTML = divs;

        let flag = true;
        $("#productList a").eq(7).prop("href","#").click(function(){
            console.log(1);
            flag = !flag;
            flag ? $(this).nextAll().slideDown():$(this).nextAll().slideUp();
        })
        
    }
}
xhr.send(null);


let main_box = document.querySelector(".main_box ul")
fetch("http://chst.vip:1234/api/getmoneyctrl").then(function(data){
    return data.json();
}).then(function(res){
    console.log(res);
    // console.log(res.result);

    let lis = "";
        let regExp = /(?<=imgurl=)[^'"]*/;
        res.result.forEach((item,index) => {
            // console.log(item);
            let url = res.result[index].productImg2.match(regExp)[0];
            lis += `<li id="${item.productId}" class="ali"><a href="#">
                        <div class="left">
                        <img src="${url}">
                        </div>
                        <div class="right">
                            <div class="title">
                                <p>
                                    ${item.productName}
                                    <span>${item.productPinkage}</span>
                                </p>
                            </div>
                            <div class="other">
                                <span>${item.productFrom}|${item.productTime}</span>
                                <span>${item.productComCount}</span>  
                            </div>
                        </div>
                    </a></li>`
        });
        main_box.innerHTML = lis;
        let aLi = document.querySelectorAll(".ali");
        console.log(aLi);
        aLi.forEach(index => {
            index.onclick = function(){
                let ID = index.id;
                console.log(ID);
                location.href = './html/moneyctrlproduct1.html?productid='+ ID
            }
        })
})

